package com.king.template;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.king.common.template.DirectiveHandler;
import com.king.common.template.TemplateDirective;
import com.king.service.MPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PostTemplate extends TemplateDirective {

    @Autowired
    MPostService mPostService;

    @Override
    public String getName() {
        return "post";
    }

    @Override
    public void execute(DirectiveHandler handler) throws Exception {
        Integer level = handler.getInteger("level");
        Integer pageNum = handler.getInteger("pn",1);
        Integer pageSize = handler.getInteger("size",2);
        Long categoryId = handler.getLong("categoryId");

        IPage page = mPostService.paging(new Page(pageNum, pageSize), categoryId, null, level, null, "created");
        handler.put(RESULTS,page).render();
    }
}
